<template>
  <div class="report-form-content">
    <div>
      <van-tabs :active="active">
        <van-tab title="预算指标单">
          <div class="tabs-list">
            <div class="report-form-list-content">
              <div class="shenpilist">
                <label>指标编码</label>
                <span>{{ obj.kpiCode }}</span>
              </div>
              <div class="shenpilist">
                <label>指标名称</label>
                <span>{{ obj.kpiName }}</span>
              </div>
              <div class="shenpilist">
                <label>日期</label>
                <span>{{ obj.kpiDate?.substring(0, 10) }}</span>
              </div>
              <div class="shenpilist">
                <label>预算年度</label>
                <span>{{ obj.year }}</span>
              </div>
              <div class="shenpilist">
                <label>支出类型</label>
                <span>{{ showDictKeyLabel('ExpenditureKpiPayType', obj.payType) }}</span>
              </div>
              <div class="shenpilist">
                <label>经费类型</label>
                <span>{{ showDictKeyLabel('ExpenditureKpiFundType', obj.fundType) }}</span>
              </div>
              <div class="shenpilist">
                <label>预算总金额</label>
                <span>￥{{ obj.amount }}</span>
              </div>
              <div class="shenpilist">
                <label>项目类型</label>
                <span>{{ showIdLabel(expenditurePtypeList, obj.expenditurePtypeId, 'name') }}</span>
              </div>
              <div class="shenpilist">
                <label>功能分类</label>
                <span>{{ showIdLabel(expenditureFunctionalList, obj.expenditureFunctionalId, 'name') }}</span>
              </div>
              <div class="shenpilist">
                <label>财政项目</label>
                <span>{{ showIdLabel(expenditureFiscalList, obj.expenditureFiscalId, 'name') }}</span>
              </div>
              <div class="shenpilist">
                <label>指标来源</label>
                <span>{{ showDictKeyLabel('ExpenditureKpiSource', obj.source) }}</span>
              </div>
              <div class="shenpilist">
                <label>项目负责人部门</label>
                <span>{{ showIdLabel(organizationList, obj.organizationId, 'organizationName') }}</span>
              </div>
              <div class="shenpilist">
                <label>项目负责人用户</label>
                <span>{{ showIdLabel(userList, obj.managerId, 'name') }}</span>
              </div>
              <div class="shenpilist">
                <label>状态</label>
                <span>{{ showEnumLabel('ExpenditureKpiState', obj.state) }}</span>
              </div>
              <div class="shenpilist">
                <label>按经济分类控制金额</label>
                <span>{{ showEnumLabel('CommonYesNo', obj.isEconomic) }}</span>
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab title="经济支出预算">
          <div class="update-log" v-for="(item,index) in items" :key="index">
            <div class="shenpilist-head" style="display: flex;align-items: center;">
              经济支出预算{{ index + 1 }}:
            </div>
            <div class="report-form-list-content">
              <div class="shenpilist">
                <label>经济分类</label>
                <span>{{ showIdLabel(expenditureEconomicList, item.expenditureEconomicId, 'name') }}</span>
              </div>
              <div class="shenpilist">
                <label>金额</label>
                <span>￥{{ item.amount }}</span>
              </div>
              <div class="shenpilist">
                <label>浮动率(上浮)</label>
                <span>{{ item.fluctuate }}%</span>
              </div>

            </div>
            <div class="report-form-list-content-1">
              <div class="shenpilist">
                <label>备注</label>
                <span>{{ item.remark }}</span>
              </div>
            </div>
          </div>
        </van-tab>
      </van-tabs>
      <el-tabs v-model="activeName" class="demo-tabs">
        <el-tab-pane label="" name="first"></el-tab-pane>
        <el-tab-pane label="" name="second" v-if="obj.isEconomic === '1'"></el-tab-pane>
      </el-tabs>
    </div>
  </div>
  <!-- <el-dialog v-model="attachmentVisible" title="附件预览" width="70%" top="2vh">
    <attachmentPreview v-model:attachmentId="previewAttachmentId" />
    <div style="text-align:right;">
      <el-button type="danger" @click="closeBtn">关闭</el-button>
    </div>
  </el-dialog> -->
</template>
<script setup>
import {ref, computed, watch} from 'vue'
import {doGet} from "@/config/http";
import {svc, showDictKeyLabel, showEnumKeyLabel, showIdLabel, getListPageSize, showEnumLabel} from "@/config/common";
import attachmentPreview from '@/views/components/base/attachmentPreview.vue'
import initListStore from '@/store/modules/initList'

const props = defineProps({
  expenditureKpiId: {
    required: true,
    type: String,
  }
})

const emit = defineEmits(['close'])

// tab 切换
let active = ref(0)
// 基本数据
let obj = ref({})
let items = ref([])

// 指标单数据
let expenditureKpiObj = ref({})
// 附件
let fileList = ref([])

let governmentList = initListStore().governmentList
let organizationList = initListStore().organizationList
let userList = initListStore().userList
let expenditurePtypeList = initListStore().expenditurePtypeList//项目类型
let expenditureFunctionalList = initListStore().expenditureFunctionalList//功能分类
let expenditureEconomicList = initListStore().expenditureEconomicList//经济分类
let expenditureFiscalList = initListStore().expenditureFiscalList//财政项目
let expenditureSubjectList = initListStore().expenditureSubjectList//会计科目

let attachmentVisible = ref(false)
let previewAttachmentId = ref('')

watch(() => props.expenditureKpiId, async val => {
  await initObj(val)
  // await initList()
},{immediate:true})

 // 获取下拉框数据列表
// async function initList() {
//   let p1 = doGet(svc, '/government/page', {pageSize: getListPageSize()}, false)
//   let p2 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false)
//   let p3 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false)
//   let p4 = doGet(svc, '/expenditure-ptype/page', {pageSize: getListPageSize()}, false)
//   let p5 = doGet(svc, '/expenditure-functional/page', {pageSize: getListPageSize()}, false)
//   let p6 = doGet(svc, '/expenditure-economic/page', {pageSize: getListPageSize()}, false)
//   let p7 = doGet(svc, '/expenditure-fiscal/page', {pageSize: getListPageSize()}, false)
//   let p8 = doGet(svc, '/expenditure-subject/page', {pageSize: getListPageSize()}, false)
//   let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8])
//   governmentList.value = resArray[0]['records']
//   organizationList.value = resArray[1]['records']
//   userList.value = resArray[2]['records']
//   expenditurePtypeList.value = resArray[3]['records']
//   expenditureFunctionalList.value = resArray[4]['records']
//   expenditureEconomicList.value = resArray[5]['records']
//   expenditureFiscalList.value = resArray[6]['records']
//   expenditureSubjectList.value = resArray[7]['records']
// }

// 获取数据
async function initObj(id) {
  obj.value = await doGet(svc, '/expenditure-kpi/' + id, {}, true)
  items.value = await doGet(svc, '/expenditure-kpi-item/listByField', {field: 'expenditureKpiId', values: id}, false)
}

function closeBtn() {
  attachmentVisible.value = false
}
</script>

<style scoped lang="scss">
.report-form-content {
  width: 100%;
  height: 52vh;
  overflow-x: hidden;
  overflow-y: auto;
}
.report-form-content-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.file-list-btn {
  display: flex;
  /* display: flex; */
  align-items: center;
  justify-content: space-between
}
.report-form-list-content .el-form-item__label {
  width: 220px !important;
}
.el-form-item__label {
  width: 220px !important;
}
.report-form-list-content {
  display: flex;
  flex-wrap: wrap;
}

.form-label {
  display: inline-flex;
  justify-content: flex-end;
  align-items: flex-start;
  flex: 0 0 auto;
  /* font-size: var(--el-form-label-font-size); */
  font-size: 16px;
  /* color: var(--el-text-color-regular); */
  color: #337ecc;
  height: 32px;
  line-height: 32px;
  padding: 0 12px 0 0;
  box-sizing: border-box;
  width: 200px;
  font-weight: bold;
}
.update-log {
  width: 100%;
  margin-top: 0;
  margin-bottom: 30px;
}
.select-list {
  width: 100%;
  margin: 30px 0;
  display: flex;
  align-items: center;
  /* justify-content: space-between; */
}
.select-list .el-radio-group {
  margin-right: 30px;
}
.select-list .el-button {
  margin-left: 30px;
}
.add-indexs {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.upload-demo {
  margin-right: 20px;
}
.file-list {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0;
}
.file-list-btns {
  display: flex;
  align-items: center;
}
.file-list-btn-span {
  color: #F56C6C;
  font-size: 12px;
}
.shenpi {
  width: 33%;
  display: flex;
  align-items: center;
  overflow: hidden;
  margin: 15px 0;
  font-size: 16px;
  border-bottom: 1px solid #eee;
}
.shenpi label {
  width: 280px;
  text-align: right;
}
.shenpi span {
  padding-left: 15px;
  display: inline-block;
  width: 500px;
}
.shenpi-1 {
  width: 100%;
  align-items:flex-start
}
.shenpi-1 label {
  width: 134px !important;
  text-align: right;
}
.shenpi-1 span {
  /* padding-left: 15px; */
  display: inline-block;
  width: 1000px;
}
.demo-tabs {
  width: 1024px !important;
}
.shenpilist {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--van-cell-background);
  box-sizing: border-box;
  width: 100%;
  padding: var(--van-cell-vertical-padding) var(--van-cell-horizontal-padding);
  overflow: hidden;
  color: var(--van-cell-text-color);
  font-size: var(--van-cell-font-size);
  // line-height: var(--van-cell-line-height);
  border-bottom: 1px solid var(--van-border-color);;
  & label {
    color: var(--van-field-label-color);
    // text-align: left;
    word-wrap: break-word;
    font-weight: 700;
  }
  & span {
    // display: block;
    box-sizing: border-box;
    // width: 100%;
    color: var(--van-field-input-text-color);
    line-height: inherit;
    // text-align: left;
    background-color: transparent;
    border: 0;
    resize: none;
    -webkit-user-select: auto;
    user-select: auto;
  }
}
.shenpilist-head {
  color: var(--van-cell-text-color);
  font-size: var(--van-cell-font-size);
  font-weight: 700;
  padding: .3125rem 0;
  padding-left: 1.125rem;
  color: #337ecc;
}
</style>
